import unittest
from selenium import webdriver
import time
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By

class jiuxian1(unittest.TestCase):

    def setUp(self):
        # 打开edge浏览器
        self.driver = webdriver.Edge()
        #  打开酒仙网
        self.driver.get('https://www.jiuxian.com/')
        # 窗口最大化
        self.driver.maximize_window()

    def tearDown(self):
        # 关闭浏览器
        self.driver.close()
        print('结束')

    def test_01(self):
        # 点击请登录,class定位
        self.driver.find_element(By.CLASS_NAME, 'headerLogin').click()
        time.sleep(2)
        # 输入账号，id定位
        self.driver.find_element(By.ID, 'userName').send_keys('15523615751')
        # 输入密码，xpath定位
        self.driver.find_element(By.XPATH, '//*[@id="password"]').send_keys('lj070130.')
        time.sleep(15)
        # 点击登录，name定位
        self.driver.find_element(By.NAME, 'bi_Usuallogin').click()
        time.sleep(2)
        # 点击弹窗确定，xpath定位
        self.driver.find_element(By.XPATH, '/html/body/div/div[4]/div[2]/div[2]/a').click()
        time.sleep(2)
        # 断言登录返回的用户名
        dy = self.driver.find_element(By.XPATH, '/html/body/div[2]/div/div[1]/div/p/span').text
        print(dy)
        self.assertIn('jxw862943923', dy)
        # # 搜索框输入五粮液,键盘事件回车
        # self.driver.find_element(By.ID, 'wd').send_keys('五粮液', Keys.ENTER)
        # time.sleep(2)
        # # 选择酒品
        # self.driver.find_element(By.XPATH, '/html/body/div[6]/div/div[2]/div[5]/ul/li[7]/div[2]/div[1]/a/img').click()
        # time.sleep(2)
        # # 切窗口
        # self.driver.switch_to.window(self.driver.window_handles[-1])
        # time.sleep(2)
        # # 断言商品价格是否一样
        # dy2 = self.driver.find_element(By.XPATH, '//*[@id="nowPrice"]/span[1]/strong').text
        # self.assertEqual('39.00', dy2)
        # # 点击加入购物车
        # self.driver.find_element(By.NAME, 'detail_jiarugouwuche').click()
        # time.sleep(2)
        # # 查看购物车
        # self.driver.find_element(By.NAME, 'detail_chakangouwuche').click()
        # time.sleep(2)
        # # 去结算
        # self.driver.find_element(By.CLASS_NAME, 'done').click()
        # time.sleep(2)
        # # 断言收货人
        # dy3 = self.driver.find_element(By.XPATH, '//*[@id="addressListDiv"]/div[2]/ul/li/div[1]/span[1]').text
        # self.assertTrue('小刘', dy3)
        # # 提交订单
        # self.driver.find_element(By.ID, 'submitOrder').click()
        # time.sleep(2)
        # # 断言订单已提交成功
        # dy4 = self.driver.find_element(By.XPATH, '/html/body/div[4]/div/div[1]/ul/li[1]').text
        # self.assertIn('订单已提交成功', dy4)
